<template>
    <div id="login">
        <div class="fa fa-chevron-left" id="back" @click="backClick"></div>
        <div id="login-title">登录</div>

        <input type="text" placeholder="请输入用户名" v-model="username" >
        <input type="password" placeholder="请输入密码" v-model="psw">
        <br>
        <button @click="loginClick" :disabled="isNull" :class="{'background':isNull}">登录</button>
        <div>{{judgeNull}}</div>
        <div>{{loginShow}}</div>
        <Toast v-model="setLoginShow">{{loginThen}}</Toast>
    </div>
</template>

<script>
import {Toast} from "vux";
export default {
    components: {
        Toast,  
    },
    data:function(){
        return {
            username:"",
            psw:"",
            isNull:true,
            setLoginShow:false
        }

    },
    methods:{
        backClick:function(){
            history.back();
        }, 
        loginClick:function(){
            var data = {
                username:this.username,
                psw:this.psw,
            };
            this.$store.dispatch("requestLogin",data);
        } 
    },
    computed:{
        loginThen:function(){
            
           return this.$store.state.loginThen.msg;
        },
        loginShow:function(){
          this.setLoginShow = this.$store.state.loginShow;
          if(this.$store.state.loginThen.msg)
          setTimeout(()=>{
              this.$store.commit("setLoginShow");
          },1000)
        },
        judgeNull:function(){
            var reg = /^[A-Za-z0-9\u4e00-\u9fa5_]+$/;
            var reg1 = /^[a-zA-Z\d_]{4,}$/;
            if(!reg.test(this.username)){
                this.isNull = true;
            }else  if(!reg1.test(this.psw)){
                this.isNull = true;
            }else{
                this.isNull = false;
            }
        },
    },
}
</script>

<style scoped>
    #login{
    background-color: #cccccc;
    height: 100vh;
    text-align: center;
}
#login-title{
    text-align: center;
    font-size: 15px;
    height: 45px;
    line-height: 45px;
    background-color: skyblue;
    font-family: 宋体;
    font-weight: 700;
}
#back{
    position: absolute;
    height: 4px;
    line-height: 45px;
    left: 15px;
}
#login input{
height: 45px;
width: 95%;
margin-left: 8px;
margin-top: 10px;
padding: 10px;
}
button{
    height: 45px;
    width: 95%;
    margin-left: 8px;
    margin-top: 10px;
    padding: 10px;
    background-color: deepskyblue;
    border-radius: 5px;
}
.background{
    background-color: #999999;
}
</style>